import os
import shutil

class FileMover:
    # 默认扩展名
    VIDEO_EXTS = {".mp4", ".avi", ".mov", ".mkv", ".flv", ".wmv"}
    IMAGE_EXTS = {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff"}

    def __init__(self, src_folder=None, video_folder=None, image_folder=None):
        self.src_folder = src_folder
        self.video_folder = video_folder
        self.image_folder = image_folder

    # Setter 方法
    def set_src_folder(self, path):
        self.src_folder = path

    def set_video_folder(self, path):
        self.video_folder = path

    def set_image_folder(self, path):
        self.image_folder = path

    def move_files(self):
        if not self.src_folder or not os.path.exists(self.src_folder):
            print(f"❌ 源文件夹不存在: {self.src_folder}")
            return

        if not self.video_folder or not self.image_folder:
            print("❌ 目标文件夹未设置")
            return

        # 确保目标文件夹存在
        os.makedirs(self.video_folder, exist_ok=True)
        os.makedirs(self.image_folder, exist_ok=True)

        for filename in os.listdir(self.src_folder):
            filepath = os.path.join(self.src_folder, filename)

            # 跳过子目录，只处理文件
            if not os.path.isfile(filepath):
                continue

            _, ext = os.path.splitext(filename)
            ext = ext.lower()  # 忽略大小写

            if ext in self.VIDEO_EXTS:
                shutil.move(filepath, os.path.join(self.video_folder, filename))
                print(f"✅ 视频文件已移动: {filename}")
            elif ext in self.IMAGE_EXTS:
                shutil.move(filepath, os.path.join(self.image_folder, filename))
                print(f"✅ 图像文件已移动: {filename}")
            else:
                print(f"⚠️ 未处理文件: {filename} (未知类型)")


if __name__ == "__main__":
    mover = FileMover()

    src = input("请输入源文件夹路径: ").strip()
    video = input("请输入视频目标文件夹路径: ").strip()
    image = input("请输入图像目标文件夹路径: ").strip()

    # 使用 setter 设置参数
    mover.set_src_folder(src)
    mover.set_video_folder(video)
    mover.set_image_folder(image)

    # 执行整理
    mover.move_files()
